package com.springcloud.ribbon.service.impl;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.springcloud.ribbon.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * @author: yc
 */
@Service
public class TestServiceImpl implements TestService {

    @Autowired
    private RestTemplate restTemplate;

    //启动断路器 fallbackMethod指定熔断方法
    @HystrixCommand(fallbackMethod = "error")
    @Override
    public String hello(String param) {
        return restTemplate.getForObject("http://eureka-client/hello/" + param, String.class);
    }


    private String error(String param){
        return "sorry, error!   param: "+ param;
    }
}
